<?php
session_start();
$pfadTiefe = str_replace($_SERVER['DOCUMENT_ROOT'], "", dirname(__FILE__)."/" ); // alle nötigen PHP funktionen einfügen
$slashCount = substr_count($pfadTiefe, '/'); // Zählen wieviele Slashes drinne sind
$ebeneTiefer = ""; 
for($i=0; $i<$slashCount; $i++){ // für jeden slash eine ebene tiefergehen
	$ebeneTiefer .= DIRECTORY_SEPARATOR . '..';
}
$pfad = dirname(__FILE__).$ebeneTiefer;
require_once($pfad."/inc/inc_general_php_functions.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Starting Homepage of Dota2 League">
<meta name="robots" content="index,follow">
<title>Dota2 League - Home</title>
<?php
	// CSS und JS
	require_once(DR.HOME_PATH_REL."/inc/inc_css_and_js.php");
	
	// Google Stuff
	require_once(DR.HOME_PATH_REL."/inc/googleStuff.php");
?>
<?php
	$MatchDetails = new MatchDetails();
	$User = new User();
	$UserStats = new UserStats();
	$Ladder = new Ladder();
	$Match = new Match();
	$Queue = new Queue();
	
	// FirstLOgin
	if(isset($_GET['firstLogin']) && $_GET['firstLogin'] == 1 && $_SESSION['user']['steamID'] > 0){
		// berechneten Elo ausrechnen
		$UserElo = new UserElo();
		$MatchMode = new MatchMode();
		$eloArray = $UserElo->getAllEloValuesOfUser($_SESSION['user']['steamID']);
		$modi = $MatchMode->getAllMatchModes();
			
		$smarty->assign('modi', $modi);
		$smarty->assign("eloArray",$eloArray);
		$smarty->assign("elo", $eloArray[1][1]['Elo']);
	}
	// statusBar
	// User count
	$userCount = $User->getUserCount();
	$matchesCount = $Match->getMatchesPlayedCount();
	$inQueueCount = $Queue->getInQueueCount();
	
	// eingeloggt
	if(isset($_SESSION['user']['steamID']) && $_SESSION['user']['steamID'] > 0){
		$steamID = $_SESSION['user']['steamID'];
		
		// User Details
		$userData = $User->getUserData($steamID);
		
		$userStats = $UserStats->getUserStats($steamID);
		
		// general ranking
		$generalRanking = $Ladder->getGeneralRanking($steamID, $userStats['Rank']);
		
		// get Notifications
		//$Profile = new Profile();
		//$notificationData = $Profile->getNotifications($steamID);
		
		// get Wall of Fame Data
		$wallOfFameData = $UserStats->getWallOfFameData();
		
		// User Credits auslesen
		$UserCredits = new UserCredits();
		$retCredits = $UserCredits->getCreditCountOfPlayer($steamID);
		$retHighestC =  $UserCredits->getHighestUserCredits();
		
		$SingleLadder = new SingleLadder();
		$bestPlayerRet = $SingleLadder->getGeneralLadderPlayers($steamID,0,null,5);
		
		$MatchMode = new MatchMode();
		$modi = $MatchMode->getAllMatchModes();
		
		$lastMatchesRet = $Match->getLastPlayedMatches(0, null);
		
		// Get Next Event
		$Event = new Event();
		$retEvent = $Event->getNextEvent();
		
		
		// Smarty zuweisungen
		$smarty->assign('steamID', $steamID);
		$smarty->assign('userData', $userData);
		$smarty->assign('userStats', $userStats['data']);
		$smarty->assign('notificationData', $notificationData['data']);
		$smarty->assign('notificationCount', $notificationData['count']);
		$smarty->assign('ranking', $generalRanking['position']);
		$smarty->assign('wallOfFameData', $wallOfFameData['data']);
		$smarty->assign('userCredits', $retCredits['data']);
		$smarty->assign('bestPlayer', $bestPlayerRet['data']);
		$smarty->assign('modi', $modi);
		$smarty->assign('lastMatches', $lastMatchesRet['data']);
		$smarty->assign('highestCredits', $retHighestC['data']);
		$smarty->assign('nextEvent', $retEvent['data']);
		
		
		$_SESSION['debug'] = p($retEvent,1);
		
		
		
	}
	
	$smarty->assign('userCount', $userCount['count']);
	$smarty->assign('matchesCount', $matchesCount['count']);
	$smarty->assign('inQueueCount', $inQueueCount['count']);
?>



</head>

<body>
<div id="wrap">
  <?php 
	 			$smarty->display('top_navi.tpl');
			?>
  
    <?php 
	 			$smarty->display('index/index.tpl');
				?>

  <!-- /container -->
</div>
<div id="footer">
  <div class="container">
    <?php $smarty->display('footer.tpl'); ?>
  </div>
</div>
<?php $smarty->display('general_stuff.tpl');?>
</body>
</html>